package com.yzi.core.collection
{
	public class HashMap implements ICollection
	{
		private var m_map:Object;
		private var m_length:int;
		
		public function HashMap()
		{
			init();
		}
		
		private function init(): void
		{
			m_map = new Object();
			m_length = 0;
		}
		
		public function Clear():void
		{
			for each(var key:String in m_map) m_map[key] = null;
			m_length = 0;
		}
		
		public function Size():int { return m_length; }
		
		public function Get($key:String): * { return m_map[$key]; }
		
		public function Put($key:String, $value:*): void
		{
			m_map[$key] = $value;
			m_length++;
		}
		
		public function Remove($key:String): void
		{
			m_map[$key] = null;
			m_length--;
		}
		
		public function KeySet(): Set
		{
			var result:Set = new Set();
			for each(var key:String in m_map)
			{
				result.set(key);
			}
			
			return result;
		}
		
		public function IsContain($object:*):Boolean
		{
			var result:Boolean = false;
			for each(var value:* in m_map) {
				if($object == value) {
					result = true;
					break;
				}
			}
			return result;
		}
		
		public function IsEmpty():Boolean { return (m_length == 0); }
		
		public function ToArray():Array
		{
			var result:Array = new Array();
			for each(var value:* in m_map)
			{
				result.push(value);
			}
			
			return result;
		}
		
		public function GetIterator():IIterator { return new MapIterator(this); }
	}
}
import com.yzi.core.collection.HashMap;
import com.yzi.core.collection.IIterator;

internal class MapIterator implements IIterator
{
	private var m_hashMap:HashMap;
	private var m_list:Array;
	private var m_cursor:int;
	private var m_size:int;
	
	public function MapIterator($hashMap:HashMap)
	{
		m_hashMap = $hashMap;
		init();
	}
	
	private function init(): void
	{
		m_list = m_hashMap.ToArray();
		m_cursor = 0;
		m_size = m_hashMap.Size();
	}
	
	public function Start(): void { m_cursor = 0; }
	
	public function Next(): * { return m_list[m_cursor++]; }
	
	public function HasNext(): Boolean { return (m_cursor < m_size); }
	
	public function get data(): * { return m_list[m_cursor]; }
	
	public function set data($object:*): void { throw new Error("Read Only"); }
}